<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Property Management</title>
  </head>
  <body>
    <script type="text/javascript">
      var newWaterFeeRecordWin;
      var editWaterFeeRecordWin;
      var newPropertyRecordWin;
      var editPropertyRecordWin;
      var newLiftRecordWin;
      var editLiftRecordWin;
      var newWaterRechargeRecordWin;
      var feeTabs;
      
      Ext.onReady(function(){
        //这里要设置一个变量，用来保存被点中的那个houseId是多少，默认是0
        var houseId = 0 ;
        var buildingType;
        var propertyId = 0;
        var liftId = 0;
        var waterFeeId = 0;
        Ext.QuickTips.init();
        Ext.BLANK_IMAGE_URL = '/javascripts/ext/resources/images/default/s.gif';
        var buildingUnitTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '<div style="float:left; width:90px">{number}</div><div style="float:left;width:70px">{sub_type}</div>{name}', '</div></tpl>');
        var buildingUnitStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/building/getAllBuildingUnits"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'name'
            }, {
              name: 'number'
            }, {
              name: 'sub_type'
            }])
        });
        //建筑单元
        var buildingUnit = new Ext.form.ComboBox({
          width:500,
          store: buildingUnitStore,
          fieldLabel: '楼座单元',
          allowBlank: false,
          blankText: "楼座单元必须选择",
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'building_id',//如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
          emptyText: '请选择楼座单元...',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '95%',
          pageSize: 50,
          //hideTrigger: false,
          //readOnly:true,
          tpl: buildingUnitTemplate,
          minChars: 3,
          editable: true,
          mode: 'remote',
          triggerAction: 'all',
          itemSelector: 'div.search-item',
          selectOnFocus:true
        });

        buildingUnit.on('select', function(combo, record, index) {
          houseDS.removeAll();
          propertyDS.removeAll();
          liftDS.removeAll();
          waterFeeDS.removeAll();
          waterRecordDS.removeAll();
          waterRechargeDS.removeAll();
          houseDS.baseParams.action_type = "building";
          houseDS.baseParams.building_id = record.get("id");
          houseDS.load();
          if (this.isExpanded()) {
            this.collapse();
          }
        });
        
        var buildingUnitFormPanel = new Ext.form.FormPanel({
          //baseCls: 'x-plain',
          labelWidth: 75,
          width: '850',
          title: '按单元搜索',
          labelAlign: 'right',
          frame : true,
          url: '/house/create',
          //defaultType: 'textfield',
          items: [{
              xtype: 'fieldset',
              defaults: {width: 700},
              title: '按单元搜索',
              border: true,
              items: [{
                  layout: 'column',
                  border: false,
                  items: [{
                      columnWidth: 1,
                      layout: 'form',
                      border: false,
                      items: [buildingUnit]
                    }]
                }]
            }]
        });
        //--------------------------按用户名或用户编号查询----------------------------------------
        var ownerInfoTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{number}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{owner}', '</div></tpl>');
        var ownerInfoStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/house/getAllHouseByOwnerInfo"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'owner'
            }, {
              name: 'number'
            }])
        });
        //业主信息
        var ownerInfo = new Ext.form.ComboBox({
          width:350,
          store: ownerInfoStore,
          fieldLabel: '业主信息',
          allowBlank: false,
          blankText: "楼座单元必须选择",
          valueField: 'id',
          displayField: 'owner',
          hiddenName: 'house_id',//如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
          emptyText: '请输入业主信息，比如姓名，编号...',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '90%',
          //pageSize: 10,
          //hideTrigger: false,
          //readOnly:true,
          tpl: ownerInfoTemplate,
          minChars: 2,
          editable: true,
          mode: 'remote',
          //triggerAction: 'all',此处没必要显示所有信息
          itemSelector: 'div.search-item',
          selectOnFocus:true
        });

        ownerInfo.on('select', function(combo, record, index) {
          houseDS.removeAll();
          propertyDS.removeAll();
          liftDS.removeAll();
          waterFeeDS.removeAll();
          waterRechargeDS.removeAll();
          houseDS.baseParams.house_id = record.get("id");
          houseDS.baseParams.action_type = "house";
          houseDS.load();
          if (this.isExpanded()) {
            this.collapse();
          }
        });

        
        var ownerInfoPanel = new Ext.Panel({
          title: '按用户信息搜索',
          height:50,
          frame:true,
          labelAlign: 'right',
          items: [{
              xtype: 'fieldset',
              defaults: {width: 700},
              title: '按用户信息搜索',
              border: true,
              items: [{
                  layout: 'column',
                  border: false,
                  items: [{
                      columnWidth: 1,
                      layout: 'form',
                      border: false,
                      items: [ownerInfo]
                    }]
                }]
            }]
        });
        //欠费用户搜索--------------------------------------------------------------------
        var owedType = new Ext.form.RadioGroup({
          //width : 220,
          fieldLabel: '欠费内容',
          //hideLabel:true,
          name:'owed_type',
          columns : 3,
          anchor: '90%',
          vertical :false,
          items:[
            {boxLabel:'物业',inputValue:'物业',name:'owed_type',checked:true},
            {boxLabel:'电梯',inputValue:'电梯',name:'owed_type'},
            {boxLabel:'水费',inputValue:'水费',name:'owed_type'}
          ]
        });
        
        var owedBeginYear = new Ext.form.ComboBox({ //combobox
          name: 'begin_year',
          fieldLabel: '起始年',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          mode: 'local',
          selectOnFocus: true,
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          readOnly: true,
          emptyText: '选择年...',
          store: new Ext.data.Store({
            data: [['2004', '2004'],['2005', '2005'],['2006', '2006'],['2007', '2007'],['2008', '2008'], ['2009', '2009'], ['2010', '2010'], ['2011', '2011'], ['2012', '2012']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });

        var owedBeginMonth = new Ext.form.ComboBox({ //combobox
          name: 'current_month',
          fieldLabel: '月',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          editable:false,
          readOnly: true,
          emptyText: '选择月...',
          store: new Ext.data.Store({
            data: [['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'],['7', '7'], ['8', '8'], ['9', '9'], ['10', '10'], ['11', '11'], ['12', '12']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });

        var owedEndYear = new Ext.form.ComboBox({ //combobox
          name: 'end_year',
          fieldLabel: '结止年',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          mode: 'local',
          selectOnFocus: true,
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          readOnly: true,
          emptyText: '选择年...',
          store: new Ext.data.Store({
            data: [['2004', '2004'],['2005', '2005'],['2006', '2006'],['2007', '2007'],['2008', '2008'], ['2009', '2009'], ['2010', '2010'], ['2011', '2011'], ['2012', '2012']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });
        owedEndYear.setValue(new Date().clearTime(true).getFullYear());

        var owedEndMonth = new Ext.form.ComboBox({ //combobox
          name: 'end_month',
          fieldLabel: '月',
          width: '90',
          resiable: true,
          typeAhead: true,
          allowBlank: false,
          handleHeight: 100, //
          displayField: 'key',
          valueField: 'value',
          selectOnFocus: true,
          mode: 'local',
          triggerAction: 'all',//这个属性非常重要,可以在选择一个值以后,依然还显示其它的值.
          editable:false,
          readOnly: true,
          emptyText: '选择月...',
          store: new Ext.data.Store({
            data: [['1', '1'], ['2', '2'], ['3', '3'], ['4', '4'], ['5', '5'], ['6', '6'],['7', '7'], ['8', '8'], ['9', '9'], ['10', '10'], ['11', '11'], ['12', '12']],
            reader: new Ext.data.ArrayReader({
              id: 0
            }, [{
                name: 'value'
              }, {
                name: 'key'
              }])
          }), //数据储存到这个comboBox
          anchor: '90%'
        });        
        owedEndMonth.setValue(new Date().getMonth()+1);
        
        var buildingUnitForOwedOwner = new Ext.form.ComboBox({
          width:350,
          store: buildingUnitStore,
          fieldLabel: '楼座单元',
          allowBlank: false,
          blankText: "楼座单元必须选择",
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'building_id',//如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
          emptyText: '请选择楼座单元...',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '90%',
          pageSize: 50,
          //hideTrigger: false,
          //readOnly:true,
          tpl: buildingUnitTemplate,
          minChars: 3,
          editable: true,
          mode: 'remote',
          triggerAction: 'all',
          itemSelector: 'div.search-item',
          selectOnFocus:true
        });

        buildingUnitForOwedOwner.on('select', function(combo, record, index) {
          houseDS.removeAll();
          propertyDS.removeAll();
          liftDS.removeAll();
          waterFeeDS.removeAll();
          waterRechargeDS.removeAll();
          houseDS.baseParams.action_type = "owed";
          houseDS.baseParams.building_id = record.get("id");
          houseDS.baseParams.owed_type = owedType.getValue().getGroupValue();
          houseDS.baseParams.end_year = owedEndYear.getValue();
          houseDS.baseParams.end_month = owedEndMonth.getValue();
          houseDS.load();
          if (this.isExpanded()) {
            this.collapse();
          }
        });
        
        var searchOwedOwnerButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            Ext.Ajax.request({
              url : '/house/getOwedOwners',
              success : function (result, request) {
                userDS.reload();
              },
              failure : function (result, request){
                Ext.MessageBox.alert("提示","通讯失败，请从新操作");
              },
              method : 'POST',
              params : {
                user_id : userId,
                authenticity_token: authToken.getValue()
              }
            });  
          }
        })
        var owedFormPanel = new Ext.form.FormPanel({
          //baseCls: 'x-plain',
          labelWidth: 55,
          width: '1000',
          title: '<font color=#DA3838>欠费业主查询</font>',
          labelAlign: 'right',
          frame : true,
          url: '/house/create',
          //defaultType: 'textfield',
          items: [{
              xtype: 'fieldset',
              defaults: {width: 1200},
              title: '条件搜索',
              border: true,
              items: [{
                  layout: 'column',
                  border: false,
                  items: [{
                      columnWidth: .2,
                      layout: 'form',
                      border: false,
                      items: [owedType]
                    }, {
                      columnWidth: .15,
                      layout: 'form',
                      border: false,
                      items: [owedEndYear]
                    }, {
                      columnWidth: .15,
                      layout: 'form',
                      border: false,
                      items: [owedEndMonth]
                    }, {
                      columnWidth: .3,
                      layout: 'form',
                      border: false,
                      items: [buildingUnitForOwedOwner]
                    }]
                }]
            }]
        });
        //-----------------------------searchTabs-------------------------------
        var searchTabs = new Ext.TabPanel({
          width:450,
          activeTab: 0,
          //frame:true,
          defaults:{autoHeight: true},
          items:[buildingUnitFormPanel,ownerInfoPanel,owedFormPanel]
        });
        //------------------------------业主Grid--------------------------------
        var houseDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/house/getAllHouses'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'number'
            },{
              name: 'building_type',
              mapping:'building.sub_type'
            },{
              name: 'owner'
            },{
              name: 'phone'
            },{
              name: 'id_card'
            },{
              name:'move_in'
            },{
              name:'area'
            },{
              name:'balance'
            },{
              name:'water_pay_year'
            },{
              name:'water_pay_month'
            },{
              name:'lift_pay_year'
            },{
              name:'lift_pay_month'
            },{
              name:'property_pay_year'
            },{
              name:'property_pay_month'
            }])
        });
        //house的CM
        var houseCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
            id: 'common',
            header: '数据库编号',
            dataIndex: 'id',
            width: 30,
            hidden:true
          },{
            header: '编号',
            dataIndex: 'number',
            width: 70
          },{
            header: '建筑类型',
            dataIndex: 'building_type',
            width: 70
          },{
            header: '业主姓名',
            dataIndex: 'owner',
            width: 70
          },{
            header: '业主电话',
            dataIndex: 'phone',
            width: 70
          },{
            header: '入住日期',
            dataIndex: 'move_in',
            renderer: Ext.util.Format.dateRenderer('Y-m-d'),
            width: 80
          },{
            header: '面积',
            dataIndex: 'area',
            width: 50
          },{
            header: '余额',
            dataIndex: 'balance',
            width: 50
          },{
            header: '物业费交费日期',
            dataIndex: 'property_pay_year',
            renderer: renderProperty,
            width: 100
          },{
            header: '电梯费交费日期',
            dataIndex: 'lift_pay_year',
            renderer: renderLift,
            width: 100
          },{
            header: '水费交费日期',
            dataIndex: 'water_pay_year',
            renderer: renderWater,
            width: 90
          }
        ]);
        //render水费日期
        function renderWater(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("water_pay_month");
        }
        //render水费日期
        function renderLift(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("lift_pay_month");
        }
        //render水费日期
        function renderProperty(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("property_pay_month");
        }
        //生成要订单的产品的Grid
        var houseGrid = new Ext.grid.GridPanel({
          store: houseDS,
          cm: houseCM,
          loadMask: true,
          //renderTo: 'editor-grid',
          //width: 830,
          height: 320,
          //frame: true,
          collapsible: true,
          //autoExpandColumn: 'common',
          title: '业主列表',
          frame: false
        });
        houseGrid.on('rowdblclick', function(gridPanel, rowIndex, e){
          buildingType = houseDS.getAt(rowIndex).get('building_type');
          houseId = houseDS.getAt(rowIndex).get('id');
          refreshOwnerFeeInfo();
        });
        
        function refreshOwnerFeeInfo(){
          houseDS.reload();
          propertyDS.removeAll();
          liftDS.removeAll();
          waterFeeDS.removeAll();
          waterRecordDS.removeAll();
          waterRechargeDS.removeAll();
          propertyDS.baseParams.house_id = houseId;
          propertyDS.load({callback: function(record, options, success){
              if(success){
                //判断是不是高层
                if(buildingType == "高层"){
                  liftDS.baseParams.house_id = houseId;
                  liftDS.load({callback: function(record, options, success){
                      if(success){
                        waterFeeDS.baseParams.house_id = houseId;
                        waterFeeDS.load({callback: function(record, options, success){
                            if(success){
                              waterRechargeDS.baseParams.house_id = houseId;
                              waterRechargeDS.load({callback: function(record, options, success){
                                  if(success){
                                    waterRecordDS.baseParams.house_id = houseId;
                                    waterRecordDS.load();
                                  }else{
                                    Ext.Msg.alert('操作','查询自来水抄表记录失败，请再次双击业主信息！');
                                  }
                                }
                              });
                            }else{
                              Ext.Msg.alert('操作','查询水费失败，请再次双击业主信息！');
                            }
                          }
                        });
                      }else{
                        Ext.Msg.alert('操作','查询电梯费失败，请再次双击业主信息！');
                      }
                    }
                  });
                }
              }else{
                Ext.Msg.alert('操作','查询物业费失败，请再次双击业主信息！');
              }
            }
          });
        }

        //设置右键菜单
        houseGrid.on('rowcontextmenu', function(housegrid, rowIndex, e){
          houseId = houseDS.getAt(rowIndex).get('id');
          buildingType = houseDS.getAt(rowIndex).get('building_type');
          e.preventDefault();
          if (buildingType=="多层"){
            liftFeeMenuItem.disable();
            waterFeeMenuItem.disable();
            waterRechargeMenuItem.disable();
          }else{
            liftFeeMenuItem.enable();
            waterFeeMenuItem.enable();
            waterRechargeMenuItem.enable();
          }
          houseRightMenu.showAt(e.getXY());
        });

        //############ 订单-右键菜单 ##########
        var waterFeeMenuItem = new Ext.menu.Item({
          text: '【水费交款】',
          handler: rightMenuNewWaterFn
        });
        var waterRechargeMenuItem = new Ext.menu.Item({
          text: '【水费充值】',
          handler: rightMenuNewWaterRechargeFn
        });
        var liftFeeMenuItem = new Ext.menu.Item({
          text: '【电梯费交款】',
          //iconCls: 'album',
          handler: rightMenuNewLiftFn
        });
        
        var houseRightMenu = new Ext.menu.Menu({
          items: [{
              handler: rightMenuNewPropertyFn,
              text: '【物业费交款】'
            },liftFeeMenuItem,waterFeeMenuItem,"-",waterRechargeMenuItem]
        });
        function rightMenuNewWaterFn(grid, rowIndex, e){
          //-----------------------------new water record win---------------------
          newWaterFeeRecordWin = new Ext.Window({
            layout: 'fit',
            width: 418,
            height: 263,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '添加水费记录',
            autoLoad: {
              url: "/fee/newWaterFeeRecord?house_id="+houseId,
              scripts: true
            }
          });
          //刷新水费
          newWaterFeeRecordWin.on("destroy",function(){
            refreshOwnerFeeInfo();
            feeTabs.activate(waterFeeGrid);
          });
          newWaterFeeRecordWin.resizable = false;
          newWaterFeeRecordWin.show();
        }
        function rightMenuNewWaterRechargeFn(grid, rowIndex, e){
          //-----------------------------new water recharge record win---------------------
          newWaterRechargeRecordWin = new Ext.Window({
            layout: 'fit',
            width: 218,
            height: 108,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '水费充值',
            autoLoad: {
              url: "/fee/newWaterRechargeRecord?house_id="+houseId,
              scripts: true
            }
          });
          //刷新水费
          newWaterRechargeRecordWin.on("destroy",function(){
            refreshOwnerFeeInfo();
            feeTabs.activate(waterRechargeGrid);
          });
          newWaterRechargeRecordWin.resizable = false;
          newWaterRechargeRecordWin.show();
        }
        function rightMenuNewPropertyFn(){
          newPropertyRecordWin = new Ext.Window({
            layout: 'fit',
            width: 415,
            height: 185,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '添加物业费记录',
            autoLoad: {
              url: "/fee/newPropertyRecord?house_id="+houseId,
              scripts: true
            }
          });
          //刷新物业费
          newPropertyRecordWin.on("destroy",function(){
            refreshOwnerFeeInfo();
            feeTabs.setActiveTab(propertyGrid);
          });
          newPropertyRecordWin.resizable = false;
          newPropertyRecordWin.show();
        }

        function rightMenuNewLiftFn(){
          newLiftRecordWin = new Ext.Window({
            layout: 'fit',
            width: 415,
            height: 185,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '添加电梯费记录',
            autoLoad: {
              url: "/fee/newLiftRecord?house_id="+houseId,
              scripts: true
            }
          });
          //刷新电梯费
          newLiftRecordWin.on("destroy",function(){
            refreshOwnerFeeInfo();
            feeTabs.setActiveTab(liftGrid);
          });
          newLiftRecordWin.resizable = false;
          newLiftRecordWin.show();
        }
        //------------------------------业主,水费记录Grid--------------------------------
        var waterFeeDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/fee/getAllWaters'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'last_meter'
            },{
              name: 'current_meter'
            },{
              name: 'meter_recording_date'
            },{
              name: 'quantity'
            },{
              name: 'unit_price'
            },{
              name:'amount'
            },{
              name:'action_date'
            },{
              name:'last_year'
            },{
              name:'last_month'
            },{
              name:'current_year'
            },{
              name:'current_month'
            },{
              name:'balance'
            },{
              name:'use_balance'
            },{
              name:'use_cash'
            },{
              name:'action_date'
            },{
              name:'created_at'
            },{
              name:'payment_method'
            },{
              name: 'editor',
              mapping:'user.name'
            }])
        });
        //waterFee的CM
        var waterFeeCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
            id: 'common',
            header: '数据库编号',
            dataIndex: 'id',
            width: 30,
            hidden:true
          },{
            header: '上次水表数',
            dataIndex: 'last_meter',
            width: 70
          },{
            header: '本次水表数',
            dataIndex: 'current_meter',
            width: 70
          },{
            header: '本次抄表日期',
            dataIndex: 'meter_recording_date',
            renderer: Ext.util.Format.dateRenderer('Y-m-d'),
            width: 100
          },{
            header: '用水量',
            dataIndex: 'quantity',
            width: 60
          },{
            header: '本次单价',
            dataIndex: 'unit_price',
            width: 60
          },{
            header: '本次金额',
            dataIndex: 'amount',
            width: 70
          },{
            header: '余额',
            dataIndex: 'balance',
            width: 60
          },{
            header: '使用上次余额',
            dataIndex: 'use_balance',
            width: 90
          },{
            header: '使用现金',
            dataIndex: 'use_cash',
            width: 70
          },{
            header: '上次交费日期',
            dataIndex: 'last_year',
            renderer: renderWaterLastDate,
            width: 90
          },{
            header: '本次交费日期',
            dataIndex: 'current_year',
            renderer: renderWaterCurrrentDate,
            width: 100
          },{
            header: '本次交费方式',
            dataIndex: 'payment_method',
            width: 90
          },{
            header: '交费操作日期',
            dataIndex: 'action_date',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          },{
            header: '操作员',
            dataIndex: 'editor',
            width: 90
          }
        ]);
        //render上次水交费结止日期
        function renderWaterLastDate(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("last_month");
        }
        //render本次水交费结止日期
        function renderWaterCurrrentDate(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("current_month");
        }
        var waterFeeGrid = new Ext.grid.GridPanel({
          store: waterFeeDS,
          cm: waterFeeCM,
          loadMask: true,
          //renderTo: 'editor-grid',
          //width: 830,
          height: 400,
          //frame: true,
          collapsible: true,
          autoScroll: true,
          title: '业主水费交款记录',
          frame: false
        });
        
        waterFeeGrid.on('rowcontextmenu', function(grid, rowIndex, e){
          waterFeeId = waterFeeDS.getAt(rowIndex).get('id');
          if (waterFeeDS.getCount()==(rowIndex+1)){
            e.preventDefault();
            editWaterRightMenu.showAt(e.getXY());
          }
        });

        var editWaterFeeMenuItem = new Ext.menu.Item({
          text: '【编辑水费】',
          iconCls: 'editItem',
          handler: rightMenuEditWaterFeeFn
        });

        var editWaterRightMenu = new Ext.menu.Menu({
          items: [editWaterFeeMenuItem]
        });

        function rightMenuEditWaterFeeFn(){
          editWaterFeeRecordWin = new Ext.Window({
            layout: 'fit',
            width: 410,
            height: 270,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '编辑水费记录',
            autoLoad: {
              url: "/fee/editWaterFeeRecord?house_id="+houseId+"&water_id="+waterFeeId,
              scripts: true
            }
          });
          //刷新物业费
          editWaterFeeRecordWin.on("destroy",function(){
            refreshOwnerFeeInfo()
          });
          editWaterFeeRecordWin.resizable = false;
          editWaterFeeRecordWin.show();
        }
        
        //------------------------------业主,物业费记录Grid--------------------------------
        var propertyDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/fee/getAllProperties'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'area'
            },{
              name: 'unit_price'
            },{
              name:'amount'
            },{
              name:'action_date'
            },{
              name:'last_year'
            },{
              name:'last_month'
            },{
              name:'current_year'
            },{
              name:'current_month'
            },{
              name:'action_date'
            },{
              name:'created_at'
            },{
              name: 'editor',
              mapping:'user.name'
            }])
        });
        //Property的CM
        var propertyCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
            id: 'common',
            header: '数据库编号',
            dataIndex: 'id',
            width: 30,
            hidden:true
          },{
            header: '面积',
            dataIndex: 'area',
            width: 70
          },{
            header: '单位价格',
            dataIndex: 'unit_price',
            width: 70
          },{
            header: '本次金额',
            dataIndex: 'amount',
            width: 70
          },{
            header: '上次交费日期',
            dataIndex: 'last_year',
            renderer: renderPropertyLastDate,
            width: 90
          },{
            header: '本次交费日期',
            dataIndex: 'current_year',
            renderer: renderPropertyCurrrentDate,
            width: 100
          },{
            header: '交费操作日期',
            dataIndex: 'action_date',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          },{
            header: '操作员',
            dataIndex: 'editor',
            width: 90
          }
        ]);
        
        //render上次物业费结止日期
        function renderPropertyLastDate(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("last_month");
        }
        //render本次物业费结止日期
        function renderPropertyCurrrentDate(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("current_month");
        }
        
        var propertyGrid = new Ext.grid.GridPanel({
          store: propertyDS,
          cm: propertyCM,
          loadMask: true,
          //renderTo: 'editor-grid',
          //width: 830,
          height: 400,
          //frame: true,
          collapsible: true,
          autoScroll:true,
          title: '业主物业费交款记录',
          frame: false
        });
        
        propertyGrid.on('rowcontextmenu', function(propertygrid, rowIndex, e){
          propertyId = propertyDS.getAt(rowIndex).get('id');
          if (propertyDS.getCount()==(rowIndex+1)){
            e.preventDefault();
            editPropertyRightMenu.showAt(e.getXY());
          }
        });
        
        var editPropertyFeeMenuItem = new Ext.menu.Item({
          text: '【编辑物业费】',
          iconCls: 'editItem',
          handler: rightMenuEditPropertyFeeFn
        });

        function rightMenuEditPropertyFeeFn(){
          editPropertyRecordWin = new Ext.Window({
            layout: 'fit',
            width: 410,
            height: 180,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '编辑物业费记录',
            autoLoad: {
              url: "/fee/editPropertyRecord?house_id="+houseId+"&property_id="+propertyId,
              scripts: true
            }
          });
          //刷新物业费
          editPropertyRecordWin.on("destroy",function(){
            refreshOwnerFeeInfo()
          });
          editPropertyRecordWin.resizable = false;
          editPropertyRecordWin.show();
        }

        var editPropertyRightMenu = new Ext.menu.Menu({
          items: [editPropertyFeeMenuItem]
        });

        //------------------------------业主,电梯费记录Grid--------------------------------
        var liftDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/fee/getAllLifts'
          }),
          reader: new Ext.data.JsonReader({
            totalLift: 'totalLift',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'area'
            },{
              name: 'unit_price'
            },{
              name:'amount'
            },{
              name:'action_date'
            },{
              name:'last_year'
            },{
              name:'last_month'
            },{
              name:'current_year'
            },{
              name:'current_month'
            },{
              name:'action_date'
            },{
              name:'created_at'
            },{
              name: 'editor',
              mapping:'user.name'
            }])
        });
        //Lift的CM
        var liftCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
            id: 'common',
            header: '数据库编号',
            dataIndex: 'id',
            width: 30,
            hidden:true
          },{
            header: '面积',
            dataIndex: 'area',
            width: 70
          },{
            header: '单位价格',
            dataIndex: 'unit_price',
            width: 70
          },{
            header: '本次金额',
            dataIndex: 'amount',
            width: 70
          },{
            header: '上次交费日期',
            dataIndex: 'last_year',
            renderer: renderLiftLastDate,
            width: 90
          },{
            header: '本次交费日期',
            dataIndex: 'current_year',
            renderer: renderLiftCurrrentDate,
            width: 100
          },{
            header: '交费操作日期',
            dataIndex: 'action_date',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          },{
            header: '操作员',
            dataIndex: 'editor',
            width: 90
          }
        ]);
        //render上次电梯费结止日期
        function renderLiftLastDate(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("last_month");
        }
        //render本次电梯费结止日期
        function renderLiftCurrrentDate(value, cellmeta, record, rowIndex, columnIndex, store){
          return value +"-"+ record.get("current_month");
        }
        var liftGrid = new Ext.grid.GridPanel({
          store: liftDS,
          cm: liftCM,
          loadMask: true,
          //renderTo: 'editor-grid',
          //width: 830,
          height: 400,
          //frame: true,
          collapsible: true,
          autoScroll:true,
          title: '业主电梯费交款记录',
          frame: false
        });
        
        liftGrid.on('rowcontextmenu', function(grid, rowIndex, e){
          liftId = liftDS.getAt(rowIndex).get('id');
          if (liftDS.getCount()==(rowIndex+1)){
            e.preventDefault();
            editLiftRightMenu.showAt(e.getXY());
          }
        });

        var editLiftFeeMenuItem = new Ext.menu.Item({
          text: '【编辑电梯费】',
          iconCls: 'editItem',
          handler: rightMenuEditLiftFeeFn
        });
        
        var editLiftRightMenu = new Ext.menu.Menu({
          items: [editLiftFeeMenuItem]
        });

        function rightMenuEditLiftFeeFn(){
          editLiftRecordWin = new Ext.Window({
            layout: 'fit',
            width: 410,
            height: 180,
            closeAction: 'destroy',
            plain: true,
            modal: true,
            constrain:true,
            title: '编辑电梯费记录',
            autoLoad: {
              url: "/fee/editLiftRecord?house_id="+houseId+"&lift_id="+liftId,
              scripts: true
            }
          });
          //刷新物业费
          editLiftRecordWin.on("destroy",function(){
            refreshOwnerFeeInfo()
          });
          editLiftRecordWin.resizable = false;
          editLiftRecordWin.show();
        }
        
        //------------------------------业主,水费充值Grid--------------------------------
        var waterRechargeDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/fee/getAllWaterRecharges'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'amount'
            },{
              name: 'balance'
            },{
              name:'created_at'
            },{
              name: 'editor',
              mapping:'user.name'
            }
          ])
        });
        //waterRecharge的CM
        var waterRechargeCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
            id: 'common',
            header: '数据库编号',
            dataIndex: 'id',
            width: 30,
            hidden:true
          },{
            header: '本次充值金额',
            dataIndex: 'amount',
            width: 100
          },{
            header: '本次充值后余额',
            dataIndex: 'balance',
            width: 100
          },{
            header: '交费日期',
            dataIndex: 'created_at',
            renderer: Ext.util.Format.dateRenderer('Y-m-d H:i'),
            width: 110
          },{
            header: '操作员',
            dataIndex: 'editor',
            width: 90
          }
        ]);
        var waterRechargeGrid = new Ext.grid.GridPanel({
          store: waterRechargeDS,
          cm: waterRechargeCM,
          loadMask: true,
          //renderTo: 'editor-grid',
          //width: 830,
          height: 400,
          //frame: true,
          collapsible: true,
          autoScroll:true,
          title: '高层用户水费充值记录',
          frame: false
        });
        //------------------------------业主,水费抄表Grid--------------------------------
        var waterRecordDS = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: '/water_meter/getWaterRecordsByOwnerId'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'current_meter'
            },{
              name: 'current_year'
            },{
              name: 'current_month'
            },{
              name: 'editor',
              mapping:'user.name'
            },{
              name: 'is_paid'
            }
          ])
        });
        //waterRecharge的CM
        var waterRecordCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),{
            id: 'common',
            header: '数据库编号',
            dataIndex: 'id',
            width: 30,
            hidden:true
          },{
            header: '水表数字',
            dataIndex: 'current_meter',
            width: 100
          },{
            header: '抄表日期',
            dataIndex: 'current_year',
            renderer: function(value, cellmeta, record, rowIndex, columnIndex, store){
              return value +"-"+ record.get("current_month");
            },
            width: 90
          },{
            header: '交费情况',
            dataIndex: 'is_paid',
            renderer: function(value, cellmeta, record, rowIndex, columnIndex, store){
              if(value == 1){
                return "<font color=green>已交费</font>";
              }else{
                return "<font color=red>未交费</font>";
              }
            },
            width: 90
          },{
            header: '操作员',
            dataIndex: 'editor',
            width: 90
          }
        ]);
        var waterRecordGrid = new Ext.grid.GridPanel({
          store: waterRecordDS,
          cm: waterRecordCM,
          //renderTo: 'editor-grid',
          //width: 830,
          height: 400,
          //frame: true,
          collapsible: true,
          autoScroll:true,
          title: '高层用户水表抄表记录',
          loadMask: true,
          frame: false
        });
        //把这些交费Grid放到Tab中----------------------------------------------
        feeTabs = new Ext.TabPanel({
          width:450,
          activeTab: 0,
          //frame:true,
          //defaults:{autoHeight: true},
          items:[propertyGrid,liftGrid,waterFeeGrid,waterRechargeGrid,waterRecordGrid]
        });
        //----------------------workbench--------------------------------------
        var findHouseWorkbenchPanel = new Ext.Panel({
          //title: '查找业主',
          //width: 350,
          height:700,
          //html: '&lt;empty panel&gt;',
          //cls:'cellpadding:10',
          layout: {
            type:'vbox',
            align:'stretch'
          },
          defaults:{margins:'5 5 5 5'},
          //bodyStyle: 'padding:15px;align:center',
          //listeners: {
          //expand: showAgileDiagram
          //},
          items:[searchTabs,houseGrid,feeTabs]
        });

        //在render之前，称把相关grid隐藏
        findHouseWorkbenchPanel.render("house_search");
      })
    </script>
    <div id="house_search"></div>
  </body>
</html>
